package nige.portable.commun;

import java.util.Random;
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import nige.portable.composant.TextAreaList;

public class MyCanvas extends Canvas implements CommandListener {
	Graphics buffer = null;
	Image image = null;
	TextAreaList ta = null;
	
	public MyCanvas() {
		setCommandListener(this);
	}
	
	public void paint(Graphics g) {
		if(buffer==null){
			image = Image.createImage(getWidth(),getHeight());
			buffer = image.getGraphics();
			
			Vector v = new Vector();
			v.addElement("AZERTY");
			v.addElement("AZTY");
			v.addElement("ALFRED");
			v.addElement("BEBE");
			v.addElement("BEBINOU");
			v.addElement("CRETINOU");
			Random ran = new Random();
			for(int i=0;i<1000;i++) {
				v.addElement(""+ran.nextInt(10000));
			}
			ta = new TextAreaList(buffer,Font.getDefaultFont(),
					"",10,10,200,v,8);
		}
		g.drawImage(image,0,0,0);
	}
	public void commandAction(Command arg0, Displayable arg1) {
	}
	public void keyPressed(int code) {
		System.out.println(code);
		ta.eventOn(code);
	}
	public void keyReleased(int code) {
	}
}
